from doctor.models import Doctor
from patient.models import Patient
from django.db import models


class Appointment(models.Model):
    patient = models.ForeignKey(Patient, on_delete=models.CASCADE)
    doctor = models.ForeignKey(Doctor, on_delete=models.CASCADE)
    subject = models.CharField(max_length=30,null=True,blank=True)
    appointment_date = models.DateField()  # 预约日期
    time_slot = models.IntegerField()  # 时间段（1-4，表示四个时间段）
    queue_number = models.IntegerField()  # 队列号码（1-15）
    # 缴费状态
    status = models.CharField(
        max_length=20,
        choices=[
            ('pending', '待缴费'),
            ('paid', '已缴费'),
            ('canceled', '已取消'),
            ('blacklisted', '黑名单'),
        ],
        default='pending'
    )
    clinc_status = models.CharField(
        max_length=20,
        choices=[
            ('InQueue', '排队中'),
            ('Called', '已叫号'),
            ('Diagnosed', '已就诊'),
            ('Suspended', '挂起'),
        ],
        default='InQueue'
    )
    created_at = models.DateTimeField(auto_now_add=True)


class Queue(models.Model):
    doctor = models.ForeignKey(Doctor, on_delete=models.CASCADE)
    patient = models.ForeignKey(Patient, on_delete=models.CASCADE)
    position = models.IntegerField()  # 队列位置
    appointment_date = models.DateField()  # 预约日期
    time_slot = models.IntegerField()  # 时间段（1-4，表示四个时间段）
    is_suspended = models.BooleanField(default=False)  # 是否挂起
    created_at = models.DateTimeField(auto_now_add=True)
    appointment = models.OneToOneField(Appointment, on_delete=models.CASCADE, related_name='queue')


class VisitDoctor(models.Model):
    doctor_id = models.ForeignKey(Doctor, on_delete=models.CASCADE)
    patient_id = models.ForeignKey(Patient, on_delete=models.CASCADE)
    visit_time = models.DateTimeField(auto_now_add=True)
